package org.myorg.v4;


import java.io.Serializable;
import java.util.Random;

public class FGene4 extends Gene4 implements Serializable {
	public int length;
	public String gene="";
	
	
	public FGene4() {
		length = 0;
	}

	/**
	 * 
	 * @param length the length of gene
	 * @param low low value of gene
	 * @param high high value of gene
	 */
	public FGene4(int length) {
		this.length = length;
				
		for(int i = 0; i < length; i++) {
			if (Math.random() > 0.5) {
				gene += "0";
			} else {
				gene += "1";
			}
		}
	}
	
	public FGene4(FGene4 gene) {
		this.gene = gene.getGene();
		this.length = gene.getLength();
		this.fitness = gene.fitness;
	}

	public int getLength() {
		return length;
	}

	public String getGene() {
		return gene;
	}
	public double getFitness() {
		return fitness;
	}

	public void setFitness(double fitness) {
		this.fitness = fitness;
	}
	
/*	public double[] getGene(int begin) {
		double res[] = new double[length-begin];
		for (int i= 0; i < length-begin; i++) {
			res[i] = gene[begin+i];
		}
		return res;
	}
	
	public double[] getGene(int begin,int end) {
		double res[] = new double[end-begin];
		for (int i= 0; i < end-begin; i++) {
			res[i] = gene[begin+i];
		}
		return res;
	}*/
	
	public char geneAt(int pos) {
		return gene.charAt(pos);
	}
	
	public void setGene(int pos, char value) {
		char[] tmp = gene.toCharArray();
		tmp[pos]=value;
		gene = new String(tmp);
	}
	
}


